﻿

module Mapparola.Client {

    export class Monkify {

        constructor() {

            //http://stackoverflow.com/questions/10296625/contenteditable-binding-for-knockoutjs
            (<any>ko.bindingHandlers).editableText = {
                init: function (element, valueAccessor) {
                    $(element).attr('contenteditable', "true");
                    $(element).on('blur', function () {
                        var observable = valueAccessor();
                        if (typeof (observable) == 'function') {
                            observable($(this).text());
                        }
                    });
                },
                update: function (element, valueAccessor) {
                    var value = <string>ko.utils.unwrapObservable(valueAccessor());
                    $(element).text(value);
                }
            };

            //-----------
        }
    }
}